package com.insurance.modules.claim.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.insurance.modules.claim.constants.AttachmentEnum;
import com.insurance.modules.claim.constants.EntityTypeEnum;
import com.insurance.modules.claim.dao.FileInfoDao;
import com.insurance.modules.claim.entity.FileInfoEntity;
import com.insurance.modules.claim.service.FileInfoService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.insurance.common.utils.PageUtils;
import com.insurance.common.utils.Query;



@Service("fileInfoService")
public class FileInfoServiceImpl extends ServiceImpl<FileInfoDao, FileInfoEntity> implements FileInfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<FileInfoEntity> page = this.page(
                new Query<FileInfoEntity>().getPage(params),
                new QueryWrapper<FileInfoEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<FileInfoEntity> listByBusinessIdAndAttachment(String businessId, AttachmentEnum attachmentEnum, EntityTypeEnum entityTypeEnum) {
        LambdaQueryWrapper<FileInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(FileInfoEntity::getBusinessId, businessId);
        if(null != attachmentEnum){
            queryWrapper.eq(FileInfoEntity::getAttachment, attachmentEnum.getCode());
        }
        if(null != entityTypeEnum){
            queryWrapper.eq(FileInfoEntity::getEntityType, entityTypeEnum.getCode());
        }
        queryWrapper.orderByAsc(FileInfoEntity::getCreateTime);
        return list(queryWrapper);
    }

}